<template>
<DIV style="height: 100%">
  <el-container style="height: 100%">
    <el-aside style="height: 100%;width: 200pxpx">
      <Menu></Menu>
    </el-aside>
    <el-main style="height: 100%">
    <h1>个人资料</h1>
      <el-form :model="form_data" :label-position="'left'">
        <el-form-item label="用户名字">
          <el-input  v-model="form_data.user">
          </el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input  v-model="form_data.password">
          </el-input>
        </el-form-item>
        <el-form-item label="用户职称" >
          <el-input  v-model="form_data.title">
          </el-input>
          </el-form-item>
        <el-form-item style="width: 200px" label="头像" >
          <p style=" border-style: dashed;
            border-color: #130303;margin-top: 30px">
          <el-upload
            class="avatar-uploader"
            action="http://localhost:8000/uploader_user_avater/"
            :show-file-list="false"
            :on-success="handleAvatarSuccess"
            :before-upload="beforeAvatarUpload"
              name="uploader_name">
            <img v-if="imageUrl" :src="imageUrl" class="avatar">
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
          </p>
        </el-form-item>
          <el-form-item>
            <el-button style="margin-top: 20px" type="primary" @click="save_User">
              保存生效
            </el-button>
          </el-form-item>
        </el-form>
    </el-main>
  </el-container>
</DIV>
</template>

<script>
import  axios from "axios";
import Menu from '../components/Menu'
export default {
  name: "User_data",
  data () {
    return{
       imageUrl: '',
      form_data:{
        user:'',
        password:'',
        title:'',
        USER_id:''

      }
    }
  },
  components:{
    Menu
  },
  methods:{
    save_User(){
      axios.post('http://localhost:8000/sava_user/',this.form_data).then(res=>{
        this.$message({
          message:'保存成功',
          type:'success',
        })
      })
    },
          handleAvatarSuccess(res, file) {
        this.imageUrl = URL.createObjectURL(file.raw);
      },
      beforeAvatarUpload(file) {
        const isJPG = file.type === 'image/jpeg';
        const isLt2M = file.size / 1024 < 2;

        if (!isJPG) {
          this.$message.error('上传头像图片只能是 JPG 格式!');
        }
        if (!isLt2M) {
          this.$message.error('上传头像图片大小不能超过 2MB!');
        }
        return isJPG && isLt2M;
      }
  },
  mounted() {axios.get('http://localhost:8000/get_Userdaa/').then(res=>{
    this.form_data=res.data;
    this.imageUrl='/static/User_img/User_img_'+res.data.user+'.jpg'
  })
  }
}
</script>


<style scoped>
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    color: #e0c9c9;
    width: 178px;
    height: 178px;
    display: block;
  }


  /*  .el-aside {*/
  /*  background-color: #D3DCE6;*/
  /*  color: #333;*/
  /*  text-align: center;*/
  /*  line-height: 200px;*/
  /*}*/

  .el-aside {
    background-color: #D3DCE6;
    text-align: center;
  }
    .el-main {
    text-align: center;
  }
</style>